package com.autoMobile.servlet.rrm;

import com.autoMobile.bean.rrmBx;
import com.autoMobile.bean.rrmSgjl;
import com.autoMobile.dao.rrmbxDao;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/addsgjlServlet2")
public class addsgjlServlet2 extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	
        // 将数据存入数据库
        rrmbxDao bxdao = new rrmbxDao();
        List<rrmBx> cph=bxdao.listCph();
        // 将车牌号列表传递给 JSP 页面
        System.out.println("List of cph: " + cph);
        request.setAttribute("cph", cph);
        // 转发到 JSP 页面
        RequestDispatcher dispatcher = request.getRequestDispatcher("employee/accident-report.jsp");
        dispatcher.forward(request, response);
    }

    

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置字符编码，防止中文乱码
        request.setCharacterEncoding("UTF-8");

        // 获取表单字段数据
        
        String sglx = request.getParameter("sglx");
        String xxms = request.getParameter("xxms");
        String sgsj = request.getParameter("sgsj");
        String sgdd = request.getParameter("sgdd");
        String jsy = request.getParameter("jsy");
        String cph = request.getParameter("cph");
        String lpje = request.getParameter("lpje");
        String zt = request.getParameter("zt");
        System.out.println("事故类型: " + sglx);
        System.out.println("事故描述: " + xxms);
        System.out.println("事故时间: " + sgsj);
        System.out.println("事故地点: " + sgdd);
        System.out.println("驾驶员: " + jsy);
        System.out.println("车牌号: " + cph);
        System.out.println("理赔金额: " + lpje);
        // 创建事故记录对象
        rrmSgjl sgjl = new rrmSgjl();
        sgjl.setSglx(sglx);
        sgjl.setXxms(xxms);
        sgjl.setSgsj(sgsj);
        sgjl.setSgdd(sgdd);
        sgjl.setJsy(jsy);
        sgjl.setCph(cph);
        sgjl.setLpje(lpje);
        sgjl.setZt(zt);


        // 将数据存入数据库
        rrmbxDao bxdao = new rrmbxDao();
        bxdao.Addsglj(sgjl);

        // 跳转到结果页面或返回反馈信息
        response.sendRedirect("/javaWeb24_12_war_exploded/sgjlServlet2");  // 假设成功后跳转到 success.jsp
    }


}
